<?php

require_once('php/config.inc.php');
require_once('php/MyDB.php');
require_once('php/PatchPanelDB.php');
require_once('php/login.php');

$auth_realm = 'My realm';


$dbc= new MyDB();  

?>
<!DOCTYPE html>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD><TITLE>Network Sockets Map - <?php echo ORG_NAME; ?></TITLE>
         <meta http-equiv="content-type" content="text/html; charset=UTF-8"></meta>
         <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
         <script type="text/javascript" src="js/jquery-ui-1.8.16.min.js"></script>
         <script type="text/javascript" src="js/tab.js"></script>
	 <script type="text/javascript" src="js/raphael-min.js"></script> 
         <script type="text/javascript" src="js/puntorete.js"></script> 
        <!-- <script type="text/javascript" src="js/jquery-ui-nmptoolbar.js"></script>-->
         <script type="text/javascript" src="js/dialogs.js"></script>
         <link rel="stylesheet" href="css/tab.css" type="text/css" media="screen"></link>
         <link rel="stylesheet" href="css/jquery-ui/smoothness/jquery-ui-1.8.16.custom.css" type="text/css" media="screen"></link>

         <script type="text/javascript">
         var floors = [];
         
<?php 

         // Open a known directory, and proceed to read its contents
         $dir = "floor_img/";
         $files = scandir($dir);
         foreach($files as $i => $file){
             $path_parts = pathinfo($files[$i]);
             if($path_parts['extension'] == 'png'){

          ?>
          floors.push (<?php echo json_encode($dbc->selectAll($path_parts['filename'])); ?>);
            <?php
                             }
}
?>
         </script>
         
</HEAD>

<BODY>
    <?php
    echo "<p>".ORG_NAME."</p>";
    ?>

    <div class="tabber" align="center">   

        
        <button class="button" onclick="newFloorDialog()" style="background: transparent url('images/button.jpg')">new floor</button>
        <button onclick="newRackDialog()" style="background: transparent url('images/button.jpg')">new rack</button>
        <button onclick="newPatchPanelDialog()" style="background: transparent url('images/button.jpg')">new patch panel</button>
        <button onclick="newSocketForm()" style="background: transparent url('images/button.jpg')">new socket</button>
        <button onclick="href='?action=logOut'" style="background: transparent url('images/button.jpg')"><a href='?action=logOut'>log out</a></button>
         <?php    
         
         $dir = "floor_img/";

                 $files = scandir($dir);
         foreach($files as $i => $file){
             $path_parts = pathinfo($files[$i]);
             if($path_parts['extension'] == 'png'){
         
         ?>
        

          <div class="tabbertab"> 
          <h2>Floor <?php echo $path_parts['filename']; ?></h2>
          
       

        <div class="mappa" id="mappa<?php echo $path_parts['filename']; ?>" style="position:absolute;top:0;left:0;right:0;bottom:0;"></div>
        
        <img src="<?php echo $dir . $path_parts['basename']; ?>" />
       
        </div>
          <?php
                      
    }
}
          ?>
    
        
    </div>
    <!-- commands toolbar replaced by buttons on toop of page-->
   <!-- <div id="nmptoolbar"></div>-->
        <!-- 1st button to upload a floor image -->
      <div id="newFloorDialog" title="Add a new Floor Image" style="display:none">
   
          <form action="floor_upload.php" method="post" enctype="multipart/form-data">
          <p>Upload a png img named exclusively with the floor nr (eg. '1.png').</p>
          <p>Include the new floor nr to the $floorsNumbers Array within the php/config.inc.php file. </p>
          <p><input type="file" name="floor_upload"/>
          <input type="submit" name="submit" value="upload"/></p>
          </form>    
      </div>
  <!-- 2nd button for instructions on how to add a new rack -->
  <div id="newRackDialog" title="Add a new Rack" style="display:none">
      <p>Modify the $racksLetters array within php/config.inc.php in order to add a new rack.</p>
  </div>
        
    <!-- 3rd button to add a new patch panel -->
      <div id="newPatchPanelDialog" title="Add a new Patch Panel" style="display:none">
      <form>
          <table>
              <tr><td><p>Floor:</p></td>
              <td><p>Rack:</p></td>
              <td><p>Patch Panel:</p></td>
              <td><p>Sockets Max nr:</p></td></tr>
              <tr><td>
              <p><select id="newPatchPanel_floor" name="floor">
         
              <?php
                    foreach($floorsNumbers as $value ){
                    echo "<option value=\"$value\" >$value</option>";
                    } 
               ?>
              </select></p>
              </td>
              <td>
              <p><select id="newPatchPanel_rack" name="rack">
               <?php 
                    foreach($racksLetters as $value ){
                    echo "<option value=\"$value\">$value</option>";
                    } 
               ?>
              </select></p>
              </td>
              <td>
              <p><input id="newPatchPanel_patchPanel" type="text" name="patchPanel" value="" size="1"/></p>
              </td>
              <td>          
              <p><input id="newPatchPanel_sockets" type="text" name="socket" value="" size="2"/></p>
              </td></tr>
              <tr><td colspan="4">
              <p><input id="newPatchPanelSubmit" type="submit" name="submit" value="submit" /></p>
              </td></tr>
        </table>
      </form>
      </div>
    
    <!-- 4th button to place a socket on the map -->
      <form id="newSocketForm" method="get" style="display:none" title="Add new Sockets">
        <?php $floorsArray = $dbc->selectFloors();
        
            ?>
        <p>floor: <select name="floorList" id="floorList" onchange="refreshRack(this.value)">  
        <option value="#">--Select--</option>  
        <?php
        foreach($floorsArray as $k){
            echo "<option value=\"$k\">$k</option>";
        }
        ?>
        </select></p>
          
        <p>rack: <select name="rackList" id="rackList" onchange="refreshPatchPanel(this.value)">
                <option value="#">--Select--</option>     
           </select></p>   
  
        <p>Patch Panel:<select name="ppList" id="ppList" onchange="showSockets(this.value)">
                <option value="#">--Select--</option>
           </select></p>
           <table id="socketsTable"></table>
         
    </form>
        <!-- <a class="button" onclick="this.blur(); newFloorDialog()"><span>new floor</span></a>
        <a class="button" onclick="this.blur(); newRackDialog()"><span>new rack</span></a>
        <a class="button" onclick="this.blur(); newPatchPanelDialog()()"><span>new patch panel</span></a>
        <a class="button" onclick="this.blur(); newSocketForm()"><span>new socket</span></a>
        <a class="button" href="index.php?action=logOut" onclick="this.blur()"><span>log out</span></a>-->
        
<?php


echo "<br><p>User logged in: {$_SESSION['username']}<br></p>";
//echo '<p><a href="?action=logOut">LogOut</a></p>';

?>
</BODY>

</HTML>
 
